﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using Ruleweaver.Rules;

namespace Ruleweaver
{
	public static class Check
	{
		public static ICheckable<T> That<T>(T target)
		{
			return new ThatCheck<T>(target);
		}

		private sealed class ThatCheck<T> : Check<T>
		{
			internal ThatCheck(T target) : base(target)
			{}

			public override bool Apply()
			{
				return true;
			}
		}
	}

	public abstract class Check<T> : ICheckable<T>
	{
		public static implicit operator bool(Check<T> invokedCheck)
		{
			Contract.Requires(invokedCheck != null);

			return invokedCheck.Apply();
		}

		protected Check(T target)
		{
			Target = target;
		}

		#region ICheckable

		public Type TargetType
		{
			get { return typeof(T); }
		}

		public T Target { get; private set; }

		object ICheckable.Target
		{
			get { return Target; }
		}

		public abstract bool Apply();

		#endregion
	}
}